Plotly and cufflinks

In this tutorial we shall discuss completely about the Plotly and Cufflinks. Topics covered in the last tutorials:

Plotly and cufflinks. 

Plotly is a very powerful library tool to visualize data plots in a very interactive way, we can plot 3d surfaces and zoom in and out those plots using plotly. This library can be used in a very straightforward way.

Cufflinks is a library that connects plotly with pandas. 

First of all, install both of these libraries in anaconda. To install plotly 

pip install plotly #and then run the cell

Pip install cufflinks #run the cell to install this library

Run these cells one after the other and it will take some time to run these cells.

Now let us import a few things in the jupyter notebook to plot those interactive plots. 

Plotly even supports offline features, so it is recommended to import as offline.

from plotly.offline import download_plotlyjs,init_notebook_mode, plot,iplot

#copy and paste the above code of line, this means connecting javascript to the Jupyter notebook and initializing other modes. These are important.

init_notebook_mode(connected=True) # then run this code for connecting js to Jupyter notebook.

Now let us define few dataframes on which we would be working on.

What if I pass a normal plot in it ( using pandas builtin data visualization ) we get a line plot

Now I would pass another parameter 

df.iplot( )

Now we will get a very interactive plot, please try it on your own.

Where ever we place the mouse cursor we get those values ( in this screenshot cursor gets removed, but the pointer was placed on the blue tip ) 

Tools on the top right :

There are few more tools that could be discovered. 

Let us disappear plot A and C

To plot different kinds such as scatter plot, bar plot, 3d plots we have pass these as strings in the parameter kind.

dataframe.plot( kind =’ ‘ )

Scatter plot:

For scatter plot we have to specify x and y parameters. Initially we don’t get a scatter plot. 

We get lines that are joining those scatter plots, to resolve this issue we have to pass another parameter mode as ‘markers’

Now let us plot bar graphs passing few aggregate function.

df.iplot( kind = ‘bar’ ) # normal bar plot

df.sum( ).iplot ( kind= ‘bar’ ) #passed a aggregate function sum( )

Surface plot:

Let us vary the appearance of the surface graph

Spread plot:

This plot takes two parameters and give two plots, one is a line plot and other is a plot of spread of each other.

Histogram:

We get a histogram which is overlapped on each other to get clear on there are two ways, either we click on the col_labels on the top right of the graph or we pass only one column label to the dataframe.

First way:

Second way:

Scatter matrix:

This plot creates histogram for each series in the data frame diagonally and displays a matrix with scatter plots of all possible pairs of series in the data frame.

Topics of the upcoming tutorial:

  • Machine learning
Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *